package Concurrent.countDownLatch.wait.latch;

import java.util.concurrent.CountDownLatch;

/**
 * Created by wangyg6 on 2017/11/29.
 * 主线程做一个工作，不过要在Task one two结束之后.可以看到Task one two顺序随机
 */
public class LatchDemo {

	public static void main(String[] args) {
		CountDownLatch latch = new CountDownLatch(3);
		new Thread(new TaskOne(latch), "TaskOne Thread").start();
		new Thread(new TaskTwo(latch), "TaskTwo Thread").start();
		new Thread(new TaskThree(latch), "TaskThree Thread").start();
		try {
			Thread.sleep((long) (Math.random() * 1000));
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("main Thread complete");
	}
}
